import java.util.ArrayList;
import java.util.List;

/**
 * @author zhaozeyang
 * @date 2018/11/2 15:07
 * @description
 */
public class 六十六 {

    public static int[] plusOne(int[] digits) {
        if (digits.length == 1 && digits[0] == 0) {
            return new int[]{1};
        }
        List<Integer> resultHold = new ArrayList<Integer>();
        boolean first = true;
        boolean add = false;
        for (int i = digits.length - 1; i >= 0; i--) {
            int current = digits[i];
            int sum = current;
            if (first || add) {
                sum = current + 1;
                first = false;
            }
            if (sum >= 10) {
                resultHold.add(sum % 10);
                add = true;
                if (i == 0) {
                    resultHold.add(1);
                }
            } else {
                resultHold.add(sum);
                add = false;
            }
        }
        int[] result = new int[resultHold.size()];
        for (int i = resultHold.size() - 1; i >= 0; i--) {
            result[i] = resultHold.get(resultHold.size() - 1 - i);
        }
        return result;
    }

    public static void main(String[] args) {
        System.out.println(plusOne(new int[]{9}));
    }
}
